﻿using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Fur.Htx.Core.Entities
{
    [Table("Sys_UserDetail")]
    public class UserDetail: Entity, IEntitySeedData<UserDetail>//, IEntityTypeBuilder<UserDetail>
    {
        /// <summary>
        /// 手机号
        /// </summary>
        [Comment("手机号")]
        public string Phone { get; set; }
        /// <summary>
        /// 地址
        /// </summary>
        [Comment("地址")]
        public string Address { get; set; }
        /// <summary>
        /// 邮箱
        /// </summary>
        [Comment("邮箱")]
        public string Email { get; set; }
        /// <summary>
        /// 用户id
        /// </summary>
        [Comment("用户id")]
        public int UserId { get; set; }
        public virtual UserInfo User { get; set; }

        public void Configure(EntityTypeBuilder<UserDetail> entityBuilder, DbContext dbContext, Type dbContextLocator)
        {
            entityBuilder.HasOne(a => a.User)
                .WithOne(a => a.Detail)
                .HasForeignKey(nameof(UserId))
                .OnDelete(DeleteBehavior.ClientSetNull);
        }

        public IEnumerable<UserDetail> HasData(DbContext dbContext, Type dbContextLocator)
        {
            return new List<UserDetail> 
            { 
                new UserDetail{ Id = 1, Email = "281267775@qq.com", Phone = "17354300837", UserId = 1, Address = "湖北省武汉市东湖高新区" }
            };
        }
    }
}
